﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BeanboxSoftware.BeanProxy;

namespace BeanboxSoftware.BeanProxyTest
{
  [TestClass]
  public class EdgeCaseTest
  {
    public delegate void FooType1<T>(ref T t);
    public delegate void FooType2<T>(int i, ref T t);

    [TestMethod]
    public void TemplateRefParameterTest()
    {
      var proxy = ProxyManager.CreateProxy<TemplateRefParameterClass>();

      var nonRefConfig = ProxyManager.GetAction<double, string>(proxy.Foo<string>);
      nonRefConfig.IsReal = false;

      proxy.Foo<string>(1.2, "hi");
      Assert.AreEqual("hi", nonRefConfig.Param2, "param 2");

      var refConfig = ProxyManager.GetMethod((FooType1<string>)proxy.Foo<string>);
      refConfig.IsReal = false;

      string str = "bye";
      proxy.Foo<string>(ref str);
      Assert.AreEqual("bye", refConfig.Access.ParameterHistory[0][0], "param 1");

      str = "other";
      var config = ProxyManager.GetMethod((FooType2<string>)proxy.Foo<string>);
      config.IsReal = false;
      proxy.Foo<string>(1, ref str);
      Assert.AreEqual("other", config.Access.ParameterHistory[0][1], "other param 1");
    }
  }

  public class TemplateRefParameterClass
  {
    public virtual void Foo<T>(ref T t)
    {
    }

    public virtual void Foo<T>(int i, ref T t)
    {
    }

    public virtual void Foo<T>(double d, T t)
    {
    }
  }
}
